package com.unism.data.resource;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.unism.data.service.InstanceService;
import com.unism.util.ResponseByJson;

@Component("instanceResource")
@Path("/instances")
public class InstanceResource {

	@Autowired
	private InstanceService instanceSerive;

	@GET	
	@Path("/select")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Response select() {
		ResponseByJson result = instanceSerive.select();
		return Response.status(200).entity(result.toJsonString())
				.header("Access-Control-Allow-Headers", "X-extra-header").allow("OPTIONS").build();
	}
	@GET	
	@Path("/select1")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Response select1() {
		ResponseByJson result = instanceSerive.select1();
		return Response.status(200).entity(result.toJsonString())
				.header("Access-Control-Allow-Headers", "X-extra-header").allow("OPTIONS").build();
	}
	@GET	
	@Path("/select2")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Response select2() {
		ResponseByJson result = instanceSerive.select2();
		return Response.status(200).entity(result.toJsonString())
				.header("Access-Control-Allow-Headers", "X-extra-header").allow("OPTIONS").build();
	}
	@GET	
	@Path("/add")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Response add() {
		ResponseByJson result = instanceSerive.add();
		return Response.status(200).entity(result.toJsonString())
				.header("Access-Control-Allow-Headers", "X-extra-header").allow("OPTIONS").build();
	}
	@GET	
	@Path("/delete")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Response delete() {
		ResponseByJson result = instanceSerive.deleteById();
		return Response.status(200).entity(result.toJsonString())
				.header("Access-Control-Allow-Headers", "X-extra-header").allow("OPTIONS").build();
	}
	@GET	
	@Path("/update")
	@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
	public Response update() {
		ResponseByJson result = instanceSerive.update();
		return Response.status(200).entity(result.toJsonString())
				.header("Access-Control-Allow-Headers", "X-extra-header").allow("OPTIONS").build();
	}
	
}
